<?
use WID\Test as Test;

class ACase1 {
	private $member;
	
	function __construct() {
		$this->member = 1;
	}
}

return array(
	'name'=>'PropertiesSpy', 
	'desc'=>'Its testing PropertiesSpy class',
	
	'each'=> array(
		'spy'=>null
	),
	
	'beforeEach'=>function(&$each) {
		$each['spy'] = new Test\PropertiesSpy();
	}, 
	
	'tests'=>array(
		'creating'=>function(&$each) {
			$spy = $this->need->PropertiesSpy->onObject($each['spy']);
			
			$this->expect($spy->valueOf('Target'))->toBeNull();
			$this->expect($spy->valueOf('ClassInfo'))->toBeNull();
			$this->expect($spy->valueOf('Property'))->toBeNull();
		},
		
		'onObject'=>function(&$each) {
			$spy = $this->need->PropertiesSpy->onObject($each['spy']);
			$each['spy']->onObject(new ACase1());
			
			$this->expect($spy->valueOf('ClassInfo'))->toBeInstanceOf('ReflectionObject');
			$this->expect($spy->valueOf('Target'))->toBeInstanceOf('ACase1');
			$this->expect($spy->valueOf('Property'))->toBeNull();
		},
		
		'has'=>function(&$each) {
			$each['spy']->onObject(new ACase1());
			
			$this->expect($each['spy']->has('member'))->toBeTrue();
			$this->expect($each['spy']->has('member1'))->toBeFalse();
		},
		
		'hasNoTarget'=>function(&$each) {
			$this->expect(function() use ($each) {
				$each['spy']->has('member');
			})->toThrow('WID\Test\PropertiesSpyException')->
					withMessage('spy not have target');
		},
		
		'valueOf'=>function(&$each) {
			$each['spy']->onObject(new ACase1());
			$this->expect($each['spy']->valueOf('member'))->toBe(1);
		},
		
		'valueOfOnNoMember'=>function(&$each) {
			$each['spy']->onObject(new ACase1());
			$this->expect(function() use ($each){
				$each['spy']->valueOf('member1');
			})->toThrow('WID\Test\PropertiesSpyException')->
					withMessage('property member1 not exists');
		},
		
		'valueOfOnNoObject'=>function(&$each) {
			$this->expect(function() use ($each) {
				$each['spy']->valueOf('member1');
			})->toThrow('WID\Test\PropertiesSpyException')->
					withMessage('spy not have target');
		},
		
		'setValueOf'=>function(&$each) {
			$each['spy']->onObject(new ACase1());
			$each['spy']->setValueOf('member')->on(2);
			$this->expect($each['spy']->valueOf('member'))->toBe(2);
		},
		
		'setValueOfOnNoObject'=>function(&$each) {
			$this->expect(function() use ($each) {
				$each['spy']->setValueOf('member')->on(2);
			})->toThrow('WID\Test\PropertiesSpyException')->
					withMessage('spy not have target');
		},
		
		'onWithoutSetValueOf'=>function(&$each) {
			$each['spy']->onObject(new ACase1());
			$this->expect(function() use ($each) {
				$each['spy']->on(2);
			})->toThrow('WID\Test\PropertiesSpyException')->
					withMessage("can't set value of undefined property name");
		}
	)
);
?>